<?php
/* this could be done in an iframe with a meta refresh tag and a transition tag.
the ideal aspect of that would be the new ads each time
*/

	$page = 1;
	if (isset($_REQUEST['page']))
		$page = $_REQUEST['page'];
	
	if ($page<1)
		$page = 1;

	$timelinetype = 'home_timeline';
	if (isset($_REQUEST['tlt']))
		$timelinetype = $_REQUEST['tlt'];

?>



<?php

	include_once("dateformat.php");
	include_once("_post.php");

	$access_token = $_SESSION['access_token'];

/* Create a TwitterOauth object with consumer/user tokens. */
	$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);

	$jsonDecode = $connection->get('statuses/'.$timelinetype, array('page' => $page, 'count' =>  8));

//print_r($jsonDecode);

?>
<span id="timelinetitle"><?php echo $access_token['screen_name']; ?></span>&nbsp;&nbsp;<?php /*<span id="timelinecount"><?php echo count($jsonDecode); ?> tweet results</span>*/ ?>
<hr id="simplehr" />
<table id="timelinetable" cellspacing="0" cellpadding="5">
<?php
	@session_start();
	$access_token = $_SESSION['access_token'];
	$suser = $access_token['user_id'];

	include_once("_visuals.php");
	$registry = getRegistry($suser);

$tempmax = "0";
	$prunecount = 0;
	foreach ($jsonDecode as $timelineEntry)
	{
		@session_start();
		$access_token = $_SESSION['access_token'];
		$topdir = "/home/glidecas/public_html/chirplace1.0.0.0.com/usr/".$access_token['user_id']."/prune/".$timelineEntry->user->id.".pne";
		$fh = @fopen($topdir, 'r');
		$pruneamount = @fread($fh, filesize($topdir));
		@fclose($fh);
	
		$threshold = rand(1, 100);

		if ($pruneamount>$threshold)
		{
			$prunecount++;
		}
		else
		{
			$timelineEntry->text = formatTweet($timelineEntry->text);
			if (strcmp(trim($timelineEntry->text), "--nopost")!=0)
			{
				$tempmax = $timelineEntry->id;
				$max = count($registry);
				$randomnum = rand(1, $max)-1;
?>
		<tr>
			<td valign="top">
				<a class="dock-item2" href="http://www.twitter.com/<?php echo $timelineEntry->user->screen_name; ?>"><img src="<?php echo $timelineEntry->user->profile_image_url; ?>" alt="(~.~)" title="<?php echo $timelineEntry->user->screen_name;?>" width="48" height="48" border="0" /></a><form action="index.php" method="GET"><input type="hidden" name="start" value="prune" /><input type="hidden" name="tuser" value="<?php echo $timelineEntry->user->id; ?>" /><input type="hidden" name="tusername" value="<?php echo $timelineEntry->user->screen_name; ?>" /><input type="image" src="images/pruneicon.jpg" alt="Prune <?php echo $timelineEntry->user->screen_name; ?>" title = "Prune <?php echo $timelineEntry->user->screen_name; ?>" value="p" /></form>
			</td>
			<td valign="top">
				<a href="http://www.twitter.com/<?php echo $timelineEntry->user->screen_name; ?>"><?php echo $timelineEntry->user->screen_name; ?></a><a href="imgtxt.php?rawtweet=<?php echo urlencode($timelineEntry->text); ?>&force=<?php echo $randomnum; ?>" style="float:right"><img src="images/icon_package_get.gif" alt="Save" title="Save" border="0" /></a>
	<?php
	/*<select title="Change the image." style="float:right" onchange="forceImage(this);"><?php
	include_once("./paths/registry.php");
	foreach($registry as $regentry)
	{
		?>
	<option name="<?php echo $regentry[2]; ?>" value="<?php echo $regentry[2]; ?>"><?php echo $regentry[2]; ?></option>
		<?php
	}
	?></select><br /><br />*/


	
?>
	<br /><br />
				<center>
<?php

preg_match('/(http:\/\/)(.*)/', $timelineEntry->text, $link);
if (empty($link[0]))
{
	$pre = "";
	$post = "";
	
}
else
{
	$pre = "<a href=\"".$link[0]."\">";
	$post = "</a>";
}
?>
				<?php echo $pre; ?>
				<img src="imgtxt.php?rawtweet=<?php echo urlencode($timelineEntry->text); ?>&force=<?php echo $randomnum; ?>" title="<?php echo urlencode($timelineEntry->text); ?>" border="0" />
				<?php echo $post; ?>
				</center>
<div id="entrysource"><?php echo formatDate($timelineEntry->created_at); ?> from <?php echo $timelineEntry->source; ?></div>
	<div style="width:100%">Image Url: <input type="text" value="http://www.chirplace.com/imgtxt.php?rawtweet=<?php echo urlencode($timelineEntry->text); ?>&force=<?php echo $randomnum; ?>" style="width:95%;" /></div>
	<div style="width:100%">Embed Code: <input type="text" value='<a href="http://www.chirplace.com/"><img src="http://www.chirplace.com/imgtxt.php?rawtweet=<?php echo urlencode($timelineEntry->text); ?>&force=<?php echo $randomnum; ?>" border="0" /></a>' style="width:95%;" /></div>
				
			</td>
		</tr>
		<tr>
			<td colspan="2"><hr id="simplehr" /></td>
		</tr>

<?php
			}
		}
	}
	
?> 
	<tr>
		<td></td>
		<td><div id="entrysource"><?php echo $prunecount; ?> posts were pruned from this list.</div></td>
	</tr>
	<tr>
		<td>
			
		</td>
		<td>
			<form action="index.php" method="GET">
			<input type="hidden" name="start" value="visualine" />
			<input type="hidden" name="page" value="<?php echo $page-1; ?>" />
			<input type="submit" value="newer" id="pagebutton" />
			</form>			
			<form action="index.php" method="GET">
			<input type="hidden" name="start" value="visualine" />
			<input type="hidden" name="page" value="<?php echo $page+1; ?>" />
			<input type="submit" value="older" id="pagebutton" />
			</form>
		</td>
	</tr>
</table>
<?php
/*
<script type="text/javascript">
function forceImage(fvoSelect)
{
	var tviIndex = fvoSelect.selectedIndex; 
 
 	var parentElem = fvoSelect.parentNode;
	var imgItem = parentElem.getElementsByTagName("img")[0];

	var sSource = "imgtxt.php?rawtweet=" + imgItem.title + "&force=" + tviIndex;

	imgItem.src = sSource;

	var divItem = parentElem.getElementsByTagName("div")[0];
	var inputItem = divItem.getElementsByTagName("input")[0];
	
	inputItem.value = "<?php echo $siteUrl; ?>/" + sSource;

	divItem.style.display = "block";

}	


</script>
*/
?>